import appservice from "./request";
const baseURL = "/connect"

export function getToken(data:URLSearchParams): Promise<TokenDto> {
    return appservice.post({
        url: `${baseURL}/token`,
        data: data,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
        },
    });
}
export function getInfo(): Promise<UserDto> {
    return appservice.post({
        url: `${baseURL}/userinfo`,
        data: {},
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
        },
    })
}

export function logOut(client_id): Promise<ResultDto> {
    const data = new URLSearchParams();
    data.append("client_id", client_id);
    return appservice.post({
        url: `${baseURL}/logout`,
        data: data.toString(),
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
        },
    });
}

export function revocatToken(data:URLSearchParams): Promise<void> {
    return appservice.post({
        url: `${baseURL}/revocat`,
        data: data,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
        },
    });
}




export class TokenDto {
    access_token: string;
    token_type: string;
    expires_in: number;
    scope: string;
    id_token: string;
    refresh_token:string;
}

export class ResultDto {
    success: boolean;
    redirectUrl: string;
}


export class UserDto {
    id: string
    phoneNumberConfirmed: boolean
    phoneNumber: string
    securityStamp: string
    emailConfirmed: boolean
    normalizedEmail: string
    email: string
    normalizedUserName: string
    password: string
    userName: string
    nickName: string
    sex: number = 1
    sexyName: string
    confirmPassWord: string
    teamCode: string
    avatar: string
    banned : boolean
    constructor() {
        this.sex = 0
    }
}